package com.kkd.kkdapp.adapter;

import java.util.List;

import com.kkd.kkdapp.R;
import com.kkd.kkdapp.http.entity.ExchangeRecordItem;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class HappyBiExchangeRecordAdapter extends BaseAdapter {

	private Context mContext;
	private LayoutInflater inflater;
	private List<ExchangeRecordItem> list;

	public HappyBiExchangeRecordAdapter(Context context,
			List<ExchangeRecordItem> list) {
		mContext = context;
		inflater = LayoutInflater.from(mContext);
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.item_exchangerecord,
					parent, false);
			holder.tv_type_item_exchangeRecord = (TextView) convertView
					.findViewById(R.id.tv_type_item_exchangeRecord);
			holder.tv_status_item_exchangeRecord = (TextView) convertView
					.findViewById(R.id.tv_status_item_exchangeRecord);
			holder.tv_number_item_exchangeRecord = (TextView) convertView
					.findViewById(R.id.tv_number_item_exchangeRecord);
			holder.tv_time_item_exchangeRecord = (TextView) convertView
					.findViewById(R.id.tv_time_item_exchangeRecord);
			holder.line_item_exchangeRecord = convertView
					.findViewById(R.id.line_item_exchangeRecord);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		if (position == 0) {
			holder.line_item_exchangeRecord.setVisibility(View.GONE);
		} else {
			holder.line_item_exchangeRecord.setVisibility(View.VISIBLE);
		}
		// 兑换产品的内容
		holder.tv_type_item_exchangeRecord.setText(list.get(position)
				.getAmount() + "元" + list.get(position).getDesc());
		// 兑换结果状态
		holder.tv_status_item_exchangeRecord.setText(list.get(position)
				.getStatus());
		// 兑换所使用的快乐币数量
		holder.tv_number_item_exchangeRecord.setText(list.get(position)
				.getCoinCount() + "个");
		// 兑换时间
		holder.tv_time_item_exchangeRecord.setText(list.get(position)
				.getCreateTime());
		return convertView;
	}

	class ViewHolder {
		TextView tv_type_item_exchangeRecord;
		TextView tv_status_item_exchangeRecord;
		TextView tv_number_item_exchangeRecord;
		TextView tv_time_item_exchangeRecord;
		View line_item_exchangeRecord;
	}
}
